﻿/* ============================================================================
(c) Copyright 2012 Hewlett-Packard Development Company, L.P.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge,publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
============================================================================ */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Schema;
using System.Xml.Serialization;
using System.Runtime.Serialization;

namespace HPCloud.Objects.Domain.Compute
{
    #region JSON Support Classes
    // Type created for JSON at <<root>>
   // [System.Runtime.Serialization.DataContractAttribute(Name = "image")]
    public partial class SingleImageClass : BaseEntity
    {
        [System.Runtime.Serialization.DataMemberAttribute()]
        public Image image;
    }

    // Type created for JSON at <<root>> for deserializing list
    [System.Runtime.Serialization.DataContractAttribute(Name = "images")]
    public partial class RootImageClass
    {
        [System.Runtime.Serialization.DataMemberAttribute()]
        public Image[] images;
    }
    #endregion
   
    [System.Runtime.Serialization.DataContractAttribute(Name = "image")]
    public class Image : BaseEntity
    {
        private DateTime _lastModified;
        private DateTime _createdDate;
        private HPCloud.Objects.DataAccess.Compute.ImageRepository.ImageStatus _status = HPCloud.Objects.DataAccess.Compute.ImageRepository.ImageStatus.IGNORE;
        private Link[] _links;
        private int _progress;
        private MetaData _metaData;

//========================================================================
/// <summary>
/// 
/// </summary>
//========================================================================
        [DataMember(Name = "progress")]
        public int Progress
        {
            get { return _progress; }
            set { _progress = value; }
        }
//========================================================================
/// <summary>
/// 
/// </summary>
//========================================================================
        [XmlArrayItem("meta")]
        [XmlArray("metadata")]
        [DataMember(Name = "metadata")]
        public MetaData MetaData
        {
            get { return _metaData; }
            set { _metaData = value; }
        }
//========================================================================
/// <summary>
/// 
/// </summary>
//======================================================================== 
        [System.Xml.Serialization.XmlElementAttribute("link", Namespace = "http://www.w3.org/2005/Atom")]
        public Link[] Links
        {
            get
            {
                return _links;
            }
            set
            {
                _links = value;
            }
        }
//========================================================================
/// <summary>
/// 
/// </summary>
//========================================================================       
        [DataMember(Name = "updated")]
        public DateTime LastModified
        {
            get
            {
                if (_lastModified == null)
                    return DateTime.UtcNow;
                else
                    return _lastModified;
            }
            set
            {
                _lastModified = value;
            }
        }
//========================================================================
/// <summary>
/// 
/// </summary>
//======================================================================== 
        [DataMember(Name = "created")]
        public DateTime CreatedDate
        {
            get
            {
                return _createdDate;
            }
            set
            {
                _createdDate = value;
            }
        }
//========================================================================
/// <summary>
/// 
/// </summary>
//======================================================================== 
        [DataMember(Name = "status")]
        public HPCloud.Objects.DataAccess.Compute.ImageRepository.ImageStatus Status
        {
            get
            {
                return _status;
            }
            set
            {
                _status = value;
            }
        }
//=========================================================================================
/// <summary>
/// 
/// </summary>
/// <returns></returns>
//=========================================================================================
        public bool IsWindowsImage
        {
            get
            {
                if (this.Name.ToUpper().Contains("WIN"))
                    return true;
                else
                    return false;
            }
        }
    }
}
